package com.ruiao.tools.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ruiao.tools.R;
import com.ruiao.tools.bean.DongtaiGuankongNowDataBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DongTaiNowDataAdapter extends RecyclerView.Adapter<DongTaiNowDataAdapter.ViewHolder> {
    Context context;
    int type;
    List<DongtaiGuankongNowDataBean.DataBean.流量Bean.ParnsBean> liuliang = new ArrayList<>();
    List<DongtaiGuankongNowDataBean.DataBean.CODBean.ParnsBeanX> cod = new ArrayList<>();
    List<DongtaiGuankongNowDataBean.DataBean.氨氮Bean.ParnsBeanXX> andan = new ArrayList<>();
    List<DongtaiGuankongNowDataBean.DataBean.PH值Bean.ParnsBeanXXXXX> ph = new ArrayList<>();
    List<DongtaiGuankongNowDataBean.DataBean.总氮Bean.ParnsBeanXXXX> zongdan = new ArrayList<>();
    List<DongtaiGuankongNowDataBean.DataBean.总磷Bean.ParnsBeanXXX> zonglin = new ArrayList<>();

    public DongTaiNowDataAdapter(Context context) {
        this.context = context;
    }

    public void setData(DongtaiGuankongNowDataBean.DataBean data, int type) {
        this.type = type;
        switch (type) {
            case 1:
                liuliang = data.get流量().getParns();
                break;
            case 2:
                cod = data.getCOD().getParns();
                break;
            case 3:
                andan = data.get氨氮().getParns();
                break;
            case 4:
                ph = data.getPH值().getParns();
                break;
            case 5:
                zongdan = data.get总氮().getParns();
                break;
            case 6:
                zonglin = data.get总磷().getParns();
                break;
        }
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.adapter_dongtai_nowdata_layout, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        if (type == 1) {
            holder.tvType.setText(liuliang.get(position).getName());
            holder.tvValue.setText(liuliang.get(position).getValue());
        } else if (type == 2) {
            holder.tvType.setText(cod.get(position).getName());
            holder.tvValue.setText(cod.get(position).getValue());
        } else if (type == 3) {
            holder.tvType.setText(andan.get(position).getName());
            holder.tvValue.setText(andan.get(position).getValue());
        } else if (type == 4) {
            holder.tvType.setText(ph.get(position).getName());
            holder.tvValue.setText(ph.get(position).getValue());
        } else if (type == 5) {
            holder.tvType.setText(zongdan.get(position).getName());
            holder.tvValue.setText(zongdan.get(position).getValue());
        } else if (type == 6) {
            holder.tvType.setText(zonglin.get(position).getName());
            holder.tvValue.setText(zonglin.get(position).getValue());
        }
    }

    @Override
    public int getItemCount() {
        if (type == 1) {
            return liuliang.size();
        } else if (type == 2) {
            return cod.size();
        } else if (type == 3) {
            return andan.size();
        } else if (type == 4) {
            return ph.size();
        } else if (type == 5) {
            return zongdan.size();
        } else if (type == 6) {
            return zonglin.size();
        } else {
            return 0;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.tv_value)
        TextView tvValue;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
